package com.gxa.service.impl;

import com.gxa.mapper.BrandMapper;
import com.gxa.pojo.Brand;
import com.gxa.service.BrandService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: saas
 * @description:
 * @author: Tirion
 * @create: 2020-09-21 16:20
 **/

@Service("brandService")
public class BrandServiceImpl implements BrandService {

    @Resource
    private BrandMapper brandMapper;

    /**
     *  添加品牌
     * @param brand 前端传入的品牌json
     * @return 影响行数
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT
    ,rollbackFor = Throwable.class)
    public Integer save(Brand brand) {

        return brandMapper.insertSelective(brand);
    }

    /**
     *  删除品牌
     * @param id 删除的目标id
     * @return 影响行数
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT
            ,rollbackFor = Throwable.class)
    public Integer deleteById(Integer id) {
        return brandMapper.deleteById(id);
    }

    /**
     *  修改品牌
     * @param brand 修改的品牌
     * @return 影响行数
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT
            ,rollbackFor = Throwable.class)
    public Integer update(Brand brand) {
        return brandMapper.update(brand);
    }

    /**
     *  模糊查询
     * @param like  用户输入的关键字
     * @return 查询到的Brand集合
     */
    @Override
    @Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT
            ,rollbackFor = Throwable.class)
    public List<Brand> fuzzyQuery(String like) {
        return brandMapper.fuzzyQuery(like);
    }


    @Override
    @Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT
            ,rollbackFor = Throwable.class)
    public List<Brand> queryAll() {
        return brandMapper.queryAll();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT
            ,rollbackFor = Throwable.class)
    public Brand nameQuery(String name) {
        return brandMapper.nameQuery(name);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT
            ,rollbackFor = Throwable.class)
    public Brand selectById(Integer id) {
        return brandMapper.selectById(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT
            ,rollbackFor = Throwable.class)
    public Integer deleteBatch(List<Integer> arr) {
        return brandMapper.deleteBatch(arr);
    }
}
